home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / p063b9s.zip / UNIT / USAGE.PAS < prev    next >
Pascal/Delphi Source File  |  1996-04-20  |  3KB  |  92 lines

  1. UNIT Usage;
  2. { ╔═════════════════════════════════════════════════════════════════════════╗ }
  3. { ║ Connection usage statistics updater          Last changed: 20.04.96  SA ║ }
  4. { ║                                                                         ║ }
  5. { ║ (C) Copyright 1989-92 by D. Wulff & S. Ager                             ║ }
  6. { ║                                                                         ║ }
  7. { ║ This source may not be given to anybody, without the written permission ║ }
  8. { ║ from The Portal Team.                                                   ║ }
  9. { ╚═════════════════════════════════════════════════════════════════════════╝ }
  10. INTERFACE
  11.  
  12. USES Use32, Dos, OpDate, PoPTypes;
  13.  
  14. PROCEDURE UpdateConnectStat(MailUser, InOut: Byte; Speed: Word; ConnStr: S80);
  15. PROCEDURE UpdateUsageStat(CONST StartTime,EndTime: DateTimeRec; StatType: Byte);
  16.  
  17. IMPLEMENTATION
  18.  
  19. USES OpString, FileUtil, Globals;
  20.  
  21.   PROCEDURE UpdateConnectStat(MailUser, InOut: Byte; Speed: Word; ConnStr: S80);
  22.   VAR
  23.     i : Integer;
  24.     Proto : S5;
  25.     f1: FILE OF TPortalStat;
  26.   BEGIN
  27.     IF StatRec^.Start.D=0 THEN
  28.     BEGIN
  29.       StatRec^.Start.D:=Today;
  30.       StatRec^.Start.T:=CurrentTime;
  31.     END;
  32.     i:=0;
  33.     REPEAT
  34.       Inc(i);
  35.     UNTIL (i>5) OR ((Cfg.Statistics.MdmProtocol[i]<>'') AND (Pos(Cfg.Statistics.MdmProtocol[i], StUpcase(ConnStr))>0));
  36.     IF i<=5 THEN Proto:=Cfg.Statistics.MdmProtocol[i] ELSE Proto:='';
  37.     WITH StatRec^.Connect DO
  38.     BEGIN
  39.       i:=-1;
  40.       REPEAT
  41.         Inc(i);
  42.       UNTIL ((Bauds[i]=Speed) AND (Protocol[i]=Proto)) OR (Bauds[i]=0);
  43.       Inc(Stat[MailUser,InOut,i]);
  44.       IF Bauds[i]=0 THEN
  45.       BEGIN
  46.         Bauds[i]:=Speed;
  47.         Protocol[i]:=Proto;
  48.       END;
  49.     END;
  50.     Assign(f1, AddBackSlash(StartPath)+MakeTaskFileName(PoPStatisticsFileName));
  51.     Rewrite(f1);
  52.     Write(f1, StatRec^);
  53.     Close(f1);
  54.   END;
  55.  
  56.   PROCEDURE UpdateUsageStat(CONST StartTime,EndTime: DateTimeRec; StatType: Byte);
  57.   VAR
  58.     i, StartHour, StartMin, StartSec, EndHour, EndMin, EndSec : Byte;
  59.     DoW : DayType;
  60.   BEGIN
  61.     IF StatRec^.Start.D=0 THEN StatRec^.Start:=StartTime;
  62.     DoW:=DayOfWeek(StartTime.D);
  63.     TimeToHMS(EndTime.T,EndHour,EndMin,EndSec);
  64.     TimeToHMS(StartTime.T,StartHour,StartMin,StartSec);
  65.     i:=StartHour;
  66.     WITH StatRec^ DO
  67.     BEGIN
  68.       REPEAT
  69.         IF i=StartHour THEN
  70.         BEGIN
  71.           IF EndHour<>StartHour THEN
  72.             Inc(Usage[StatType,DoW,i],60-StartMin)
  73.           ELSE
  74.             Inc(Usage[StatType,DoW,i],EndMin-StartMin);
  75.         END ELSE
  76.         BEGIN
  77.           IF i<>EndHour THEN
  78.             Inc(Usage[StatType,Dow,i],60)
  79.           ELSE
  80.             Inc(Usage[StatType,DoW,i],EndMin);
  81.         END;
  82.         Inc(i); IF i>23 THEN
  83.         BEGIN
  84.           i:=0;
  85.           DoW:=Succ(DoW);
  86.         END;
  87.       UNTIL (i>EndHour) Or ((EndHour=23) and (i=0));
  88.     END;
  89.   END;
  90.  
  91. END.
  92.